// pages/studyRecord/phrase/phrase.js
//获取应用实例
const app = getApp();
const httpUtils = require('../../../utils/httpUtils.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    pageSize: 20,
    hasMoreData: false,
    phraseList: [],
    innerAudioContext: new Object(),
    imageurl: 'https://yxpmaterial.oss-cn-beijing.aliyuncs.com/',
    selectedIndex: -1, //选中条目的下标
    id: 1,  //第几组的组别id
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    that.setData({
      id: options.id
    })
    //初始化audio
    that.data.innerAudioContext = wx.createInnerAudioContext();
    that.data.innerAudioContext.autoplay = false;
    that.data.innerAudioContext.loop = false;
    that.getPharseDetail();
  },

  getPharseDetail:function(){
    let that = this;
    wx.showLoading({
      title: '',
      mask: true
    })
    httpUtils.getphraseDetail({
      access_token: app.globalData.studentInfo.access_token ? app.globalData.studentInfo.access_token : app.globalData.access_token,
      id: that.data.id,
    }).then((res) => {
      that.setData({
        phraseList: res.data,
      })
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

 /**
   *点击单词条目，播放读音
   */
  playWordVoice:function(e){
    this.data.innerAudioContext.stop();
    let index = e.currentTarget.dataset.index;
    let audios = e.currentTarget.dataset.audiosrc;
    console.log("点击了条目",index)
    this.setData({
      selectedIndex: index
    })
    this.data.innerAudioContext.src = audios;
    this.data.innerAudioContext.play();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})